package admin

import (
	"github.com/gin-gonic/gin"
	"go_auth/ext/app"
	"go_auth/ext/e"
	"go_auth/ext/settings"
	"go_auth/servers/admins"
	"go_auth/utils/commons"
	"net/http"
)

func BlackList(c *gin.Context) {
	ip := c.PostForm("ip")
	opt := c.PostForm("type")
	var appG = app.Gin{C: c}
	code := e.Success

	if opt == settings.Add {
		t := c.PostForm("time")
		i, f := commons.StrToInt(t)
		if !f {
			appG.Response(http.StatusOK, e.AtoB, ip)
			return
		}
		if !admins.AddBlackList(ip, ip, i) {
			code = e.AddError
		}
	} else if opt == settings.Delete {
		admins.DeleteBlackList(ip)
	} else {
		code = e.ParamsError
	}
	appG.Response(http.StatusOK, code, ip)
}
